/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package runebound.ui.combate;

import javax.swing.JToggleButton;
import runebound.manejadores.RBControladorJuego;
import runebound.manejadores.eventos.RBEventoNuevoTurno;
import runebound.modelo.heores.experiencia.Atributo;
import runebound.modelo.heores.experiencia.Experiencia;

/**
 *
 * @author Miguel (alakat@gmail.com)
 */
public class RBSubirNivelDialog extends javax.swing.JDialog {

    private Atributo atributoSeleccionado;
    /**
     * Creates new form RBSubirNivelDialog
     */
    public RBSubirNivelDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToggleButton1 = new javax.swing.JToggleButton();
        jLabel1 = new javax.swing.JLabel();
        menteButton = new javax.swing.JToggleButton();
        fisicoButton = new javax.swing.JToggleButton();
        magiaButton = new javax.swing.JToggleButton();
        fatigaButton = new javax.swing.JToggleButton();
        vidaButton = new javax.swing.JToggleButton();
        aceptarBoton = new javax.swing.JButton();

        jToggleButton1.setText("+2 Mente");
        jToggleButton1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Subida de nivel");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("Indique la subida de nivel deseada");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, -1, -1));

        menteButton.setSelected(true);
        menteButton.setText("+2 Mente");
        menteButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menteButtonActionPerformed(evt);
            }
        });
        getContentPane().add(menteButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 80, 50));

        fisicoButton.setText("+2 Fisico");
        fisicoButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        fisicoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fisicoButtonActionPerformed(evt);
            }
        });
        getContentPane().add(fisicoButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 50, 80, 50));

        magiaButton.setText("+2 Magia");
        magiaButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        magiaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                magiaButtonActionPerformed(evt);
            }
        });
        getContentPane().add(magiaButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 50, 80, 50));

        fatigaButton.setText("+1 Fatiga");
        fatigaButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        fatigaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fatigaButtonActionPerformed(evt);
            }
        });
        getContentPane().add(fatigaButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 50, 80, 50));

        vidaButton.setText("+1 Vida");
        vidaButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        vidaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vidaButtonActionPerformed(evt);
            }
        });
        getContentPane().add(vidaButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 50, 80, 50));

        aceptarBoton.setText("Aceptar");
        aceptarBoton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarBotonActionPerformed(evt);
            }
        });
        getContentPane().add(aceptarBoton, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 110, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton1ActionPerformed

    private void menteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menteButtonActionPerformed

        this.menteButton.setSelected(true);
        this.openAll(this.menteButton);
        this.atributoSeleccionado = Atributo.MENTE;
    }//GEN-LAST:event_menteButtonActionPerformed

    private void fisicoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fisicoButtonActionPerformed
        
        this.fisicoButton.setSelected(true);
        this.openAll(fisicoButton);
        this.atributoSeleccionado = Atributo.FISICO;
    }//GEN-LAST:event_fisicoButtonActionPerformed

    private void magiaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_magiaButtonActionPerformed
        
        this.magiaButton.setSelected(true);
        this.openAll(magiaButton);
        this.atributoSeleccionado = Atributo.MAGIA;
    }//GEN-LAST:event_magiaButtonActionPerformed

    private void fatigaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fatigaButtonActionPerformed
        
        this.fatigaButton.setSelected(true);
        this.openAll(fatigaButton);
        this.atributoSeleccionado = Atributo.FATIGA;
    }//GEN-LAST:event_fatigaButtonActionPerformed

    private void vidaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vidaButtonActionPerformed
        this.vidaButton.setSelected(true);
        this.openAll(vidaButton);
        this.atributoSeleccionado = Atributo.VIDA;
    }//GEN-LAST:event_vidaButtonActionPerformed

    private void aceptarBotonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarBotonActionPerformed
        int valor = 1;
        if(this.atributoSeleccionado==Atributo.MENTE||
                this.atributoSeleccionado == Atributo.FISICO||
                this.atributoSeleccionado == Atributo.MAGIA){
            valor=2;
        }
        Experiencia exp = new Experiencia(valor, 
                atributoSeleccionado,
                RBControladorJuego.getInstance().getPuntoDeExperienciaPorNivel());
        RBControladorJuego.getInstance().getHeroeActivo().addExperiencia(exp);
        this.setVisible(false);
        RBControladorJuego.getInstance().recibirEvento(new RBEventoNuevoTurno());
    }//GEN-LAST:event_aceptarBotonActionPerformed

   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptarBoton;
    private javax.swing.JToggleButton fatigaButton;
    private javax.swing.JToggleButton fisicoButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton magiaButton;
    private javax.swing.JToggleButton menteButton;
    private javax.swing.JToggleButton vidaButton;
    // End of variables declaration//GEN-END:variables

    private void openAll(JToggleButton button) {
        if(this.menteButton!=button){
            this.menteButton.setSelected(false);
        }
        if(this.fisicoButton!=button){
            this.fisicoButton.setSelected(false);
        }
        if(this.magiaButton!=button){
            this.magiaButton.setSelected(false);
        }
        if(this.vidaButton!=button){
            this.vidaButton.setSelected(false);
        }
        if(this.fatigaButton!=button){
            this.fatigaButton.setSelected(false);
        }
    }
}
